a = [6, 1, 2, 5, 4, 3, 9, 7, 10, 8]
range_queue = []

range_queue.append((0, len(a) - 1))

while len(range_queue) > 0:
    left, right = range_queue[0]
    t = left
    range_queue = range_queue[1:]
    i = left
    j = right
    while(i != j):
        while(a[j] >= a[t] and i < j):
            j -= 1
        while(a[i] <= a[t] and i < j):
            i += 1
        if i < j:
            a[i], a[j] = a[j], a[i]

    a[t], a[i] = a[i], a[t]
    if left < i - 1:
        range_queue.append((left, i - 1))

    if i + 1 < right:
        range_queue.append((i + 1, right))

print(a)
    